#include <stdio.h>
#include <string.h>
#define iMAX_STR_LEN 1024
int main(void)
{
    // 定义一个字符串，并显式初始化
    char str[iMAX_STR_LEN] = {0};
    // 从键盘读入一个字符串str
    printf("Please input a line of string:\n");
    fgets(str, iMAX_STR_LEN, stdin);
    printf("get a string: \"%s\"\n", str);
    // 追踪前一个字符和当前字符
    char cPrevious = ' ';
    char cCurrent = '\0';
    int iNum = 0;
    // 遍历字符串中每一个有效字符
    //FOR i := 0 to strlen(str) - 1 DO 
    int i = 0;
    for(i = 0; i <= (int)strlen(str) - 1; i++)
    {
        char cCurrent = str[i];
        if ((cCurrent != ' ') && (cPrevious == ' '))
        {
            // 发现新单词
            iNum++;
        }
        cPrevious = cCurrent;
    }
    printf("num=%d\n", iNum);
    return 0;
}